<template>
  <div class="dialog-box" v-show="showDialog">
    <div class="dialog-container">
      <div class="content" v-html="content"></div>
      <div class="btn-box" @click="sureBtn" v-if="type == 'default'">
        <button type="button" class="sure-btn">{{sureText}}</button>
      </div>
      <div class="btn-box" v-else>
        <div class="left-btn" @click="closeBtn">
          <button type="button" class="cancel">{{cancelText}}</button>
        </div>
        <div class="right-btn" @click="confirmBtn">
          <button type="button" class="sure">{{confirmText}}</button>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
  export default {
    props: {
      value: {},
      type: {
        type: String,
        default: ''
      },
      content: {
        type: String,
        default: ''
      },
      cancelText: {
        type: String,
        default: '取消'
      },
      confirmText: {
        type: String,
        default: '确认'
      },
      sureText: {
        type: String,
        default: '确认'
      }
    },
    data() {
      return {
        showDialog: false
      }
    },
    methods: {
      closeBtn() {
        this.showDialog = false;
        this.$emit('cancel');//触发自定义函数
      },
      confirmBtn() {
        this.$emit('confirm');
        this.showDialog = false;
      },
      sureBtn() {
        this.$emit('sure');
        this.showDialog = false;
      }
    },
    mounted() {
      this.showDialog = this.value;
    },
    watch: {
      value(newVal, oldVal) {
        this.showDialog = newVal;
      },
      showMask(val) {
        this.$emit('input', val);
      }
    },
  }
</script>

<style lang="less" scoped>


  .dialog-box {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    .dialog-container {
      position: relative;
      width: 7.32rem;
      height: 3.787rem;
      background: rgba(255, 255, 255, 1);
      border-radius: 0.173rem;
      box-sizing: border-box;
      .content {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 90%;
        margin: 0 auto;
        height: 2.6rem;
        font-size: 0.387rem;
        color: rgba(51, 51, 51, 1);
      }
      .btn-box {
        display: flex;
        width: 100%;
        height: 1.187rem;
        border-top: 1px solid rgba(230, 230, 230, 1);
        .left-btn {
          width: 3.667rem;
          height: 1.173rem;
          border-right: 1px solid rgba(230, 230, 230, 1);
          .cancel {
            border-radius: 0rem 0rem 0rem 0.173rem;
            width: 100%;
            height: 1.173rem;
            line-height: 1.173rem;
            font-size: 0.44rem;
            color: rgba(146, 146, 146, 1);
            background: #FFF;
          }
        }
        .right-btn {
          width: 3.653rem;
          height: 1.173rem;
          .sure {
            border-radius: 0rem 0rem 0.173rem 0rem;
            width: 100%;
            height: 1.173rem;
            line-height: 1.173rem;
            font-size: 0.44rem;
            color: rgba(60, 175, 255, 1);
            background: #FFF;
          }
        }
        .sure-btn {
          border-radius: 0rem 0rem 0.173rem 0.173rem;
          width: 100%;
          height: 1.173rem;
          line-height: 1.173rem;
          font-size: 0.44rem;
          color: rgba(60, 175, 255, 1);
          background: #FFF;
        }
      }
    }
  }


</style>
